public abstract class Component {
    public void add( Component child ) {}
    public void remove (Component child) {}
}

public class Composite extends Component {
    public void add( Component child ) {}
    public void remove (Component child) {}
}

public class Leaf extends Component {
    public void add( Component child ) {
        throw new UnSupportedOperationException();
    }
    public void remove (Component child) {}
}



public class client () {
    public static void main (String args[]) {
        Componet root = new Composite();
        Component c1 = new Composite();
        Component c2 = new Composite();

        Component leaf1 = new Leaf();
        Component leaf2 = new Leaf();

        root.add(c1);
        root.add(c2);

        c1.add(leaf1);
        c2.add(leaf2);

        root.remove();
    }
}


public abstract class Drinking { // 饮料的抽象类
    final void init () {
        boilWater();
        brew();
        pourInCup();
        addCondiments();
    }

    void boilWater() {
        System.out.printIn('把水煮沸');
    }
    abstract void brew() {}
    abstract void pourInCup() {}
    abstract void addCondiments() {}
}

public class Coffee extends Drinking {
    @Override
    void brew() {
        System.out.printIn('用沸水冲泡咖啡')
    }
    @Override
    void pourInCup() {
        System.out.printIn('把咖啡倒进杯子')
    }
    @Override
    void addCondiments() {
        System.out.printIn('加糖和牛奶')
    }
}

public class Tea extends Drinking {
    @Override
    void brew() {
        System.out.printIn('用沸水浸泡茶叶')
    }
    @Override
    void pourInCup() {
        System.out.printIn('把茶倒进杯子')
    }
    @Override
    void addCondiments() {
        System.out.printIn('加柠檬')
    }
}

public class Test {
    private static void prepareRecipe(Drinking drinking) {
        drinking.init();
    }

    public static void main (String args[]) {
        Drinking coffee = new Coffee();
        prepareRecipe(coffee)

        Drinking tea = new Tea();
        prepareRecipe(tea);
    }
}
